package com.liu.voluntary.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

@Slf4j
@Component   //把处理器加到ioc容器中
public class MyMetaObjectHandler implements MetaObjectHandler {

    //插入时填充
    @Override
    public void insertFill(MetaObject metaObject) {
        log.info("start insert");
        this.setFieldValByName("registerDate",new Date(),metaObject);
        this.setFieldValByName("updateDate",new Date(),metaObject);

        //报名时间
        this.setFieldValByName("createTime",new Date(),metaObject);

    }

    @Override
    public void updateFill(MetaObject metaObject) {
        log.info("start update");

        this.setFieldValByName("updateDate",new Date(),metaObject);
    }


}
